package com.situ.mall.admin.util;

import com.situ.mall.admin.entity.Administrator;


/**
 * ClassName: RequestUtil
 * Package: com.situ.store.util
 * Description:
 *
 * @Author Darling_达
 * @Create 2023-03-09 9:24
 * @Version 1.0
 */
public class RequestUtil {

    private static final String CURRENT_ADMIN = "CURRENT_ADMINISTRATOR";


    /**
     * 设置 session 的属性
     * @param key 键
     * @param value 值
     */
    public static void setAttribute(String key, Object value){
        com.situ.mall.base.util.RequestUtil.getSession().setAttribute(key, value);
    }

    /**
     *
     *获取 session 中的属性值
     * @param key 键
     * @return 值
     */
    public static Object getAttribute(String key){
        return com.situ.mall.base.util.RequestUtil.getSession().getAttribute(key);
    }


    /**
     * 保存当前登录用户进session
     * @param administrator 登录的用户
     */
    public static void current(Administrator administrator){
        setAttribute(CURRENT_ADMIN,administrator);
    }


    /**
     * 清除 session 中的某个属性
     */
    public static void removeAttribute(){
        com.situ.mall.base.util.RequestUtil.getSession().removeAttribute(CURRENT_ADMIN);
    }

    /**
     * 获取当前登录的用户
     * @return 返回该登录的用户
     */
    public static Administrator getCurrent(){
        Object obj = com.situ.mall.base.util.RequestUtil.getSession().getAttribute(CURRENT_ADMIN);
        if (null == obj){
            return null;
        } else {
            return (Administrator) obj;
        }
    }

    /**
     * 设置session的某个属性值
     * @param administrator 设置 administrator
     */
    public static void setCurrent(Administrator administrator){
        com.situ.mall.base.util.RequestUtil.getSession().setAttribute(CURRENT_ADMIN, administrator);
    }

}
